package com.weipai.springboot.module.mapper;

import com.weipai.springboot.model.Customer;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;

import java.util.List;
import java.util.Map;

/**
 * 客户
 */
public interface CustomerMapper {

    //分页查询
    List<Customer> selectAllByDel(@Param("del") int del, @Param("search") String search,
                                  @Param("sort") String sort, @Param("way") String way);

    //查询用户详情
    Customer getCustomerById(String id);

    //验证此手机号是否注册
    int getCustomerByMobile(String mobile);

    //删除
    @Update("update c_customer set customer_del=-1, del_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            "where customer_id=#{id}")
    int updateDel(String id);

    //批量删除
    int batchDeleteById(String[] id);

    //验证此昵称是否有人使用
    int verifyCustomerByNickname(String nickname);

    //更改用户的昵称
    @Update("update c_customer set customer_nickname=#{nickname}, del_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            "where customer_id=#{id}")
    int updateNicknameById(@Param("id") String customerId, @Param("nickname") String nickname);

    //绑定支付宝账号
    @Update("update c_customer set customer_real_name=#{realName}, update_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
            ", alipay_account=#{alipayAccount} where customer_id=#{id}")
    int bindingAlipayAccount(@Param("id") String customerId, @Param("alipayAccount") String alipayAccount,
                             @Param("realName") String realName);

    //获取支付宝账号详细信息
    Map<String, Object> getAlipayAccountCustomerId(String id);

    Customer getCustomerByLoginName(@Param("customerLoginName") String customerLoginName);

    List<Customer> getCustomerByAdminCode(@Param("adminCode") String adminCode);

    List<Customer> getMyTeams(@Param("adminCode") String adminCode);

    //重置密码
    int updateByPrimaryKey22(@Param("mobile") String mobile, @Param("customerPassword") String customerPassword);

    //更改会员的等级
    @Update("update c_customer set member_level_id=#{memberLevelId}, remark=#{remark} where customer_id=#{id}")
    int changeCustomerMemberLevel(@Param("id") String customerId, @Param("memberLevelId") String memberLevelId,
                                  @Param("remark") String remark);

    //更改会员的类别
    @Update("update c_customer set customer_category_id=#{categoryId} where customer_id=#{id}")
    int changeCustomerCategory(@Param("id") String customerId, @Param("categoryId") String categoryId);

    //更改用户信誉值的余额
    @Update("update c_customer set use_reputation=#{reputation} where customer_id=#{customerId}")
    int updateCustomerReputation(@Param("customerId") String customerId, @Param("reputation") int reputation);

    //查出用户的总数量
    int getCustomerAmount();

    int updateByPrimaryKeySelective(Customer customer);

    //   验证码验证  重置手机号
    int resetPhone(@Param("customerLoginName") String customerLoginName, @Param("customerId") String customerId, @Param("customerPassword") String password);


    List<Map<String, Object>> list(@Param("start") Integer start,
                                   @Param("end") Integer size,
                                   @Param("type") String type,
                                   @Param("search") String search);

    Integer listByPageAmount(@Param("type") String type, @Param("search") String search);

    Map<String, Object> getCenterCustomerById(@Param("customerId") String customerId);

    @Update("update c_customer set customer_category_id=#{customerCategoryId} where customer_id=#{customerId}")
    int updateCustomerCategoryId(@Param("customerId") String customerId, @Param("customerCategoryId") String customerCategoryId);

    //微信第三方登录
    Customer selectByWxUid(String wxUid);

    //更改用户的状态
    @Update("update c_customer set customer_status=#{status} where customer_id=#{id}")
    int changeStatus(@Param("id") String id, @Param("status") Integer status);

    //查询某一员工的推荐用户
    List<Map<String, Object>> listByAdminCode(@Param("start") Integer start,
                                              @Param("end") Integer size,
                                              @Param("adminCode") String adminCode,
                                              @Param("search") String search);

    //查询某一员工的推荐用户数量
    Integer listByAdminCodeAmount(@Param("adminCode") String adminCode,
                                  @Param("search") String search);

    int deleteByPrimaryKey(String customerId);

    int insert(Customer record);

    int insertSelective(Customer record);

    Customer selectByPrimaryKey(String customerId);

    int updateByPrimaryKey(Customer record);

    //对外接口  返回用户信息
    List<Map<String, Object>> getCustomerMessage();

    //更改微信open
    @Update("update c_customer set wx_oppenid=#{openId} where customer_id=#{id}")
    void updateByOppenID(@Param("openId") String openId, @Param("id") String id);

    @Update("UPDATE c_customer c set c.hcash_money =#{hcashMoney} WHERE c.customer_id =#{customerId}")
    int updateByHaveCashMoney(@Param("hcashMoney") int hcashMoney, @Param("customerId") String customerId);
}